﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Thenu.SpeechToText
{
    public partial class FrmThreadTask : Form
    {
        public FrmThreadTask()
        {
            InitializeComponent();
        }

        private void btnCopy_Click(object sender, EventArgs e)
        {
            backgroundWorker1.RunWorkerAsync();
        }

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                FileInfo file = new FileInfo(@"F:\OSTool\OS\Pure_GhostWin7x64v10.5.iso");
                using (FileStream streamFile = file.OpenRead())
                {
                    FileStream stramWrite = new FileStream(@"F:\OSTool\OS\Copy\Pure_GhostWin7x64v10.5.iso", FileMode.Create);

                    double fileLength = streamFile.Length;
                    byte[] buffer = new byte[1000];
                    while (streamFile.Read(buffer, 0, buffer.Length) > 0)
                    {
                        stramWrite.Write(buffer, 0, buffer.Length);
                        backgroundWorker1.ReportProgress( (int)((stramWrite.Length / fileLength) * 100));
                    }
                    streamFile.CopyTo(stramWrite);
                    stramWrite.Flush();
                    stramWrite.Close();
                }


            }
            catch (Exception)
            {

                throw;
            }
        }

        private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            try
            {
                progressBar1.Value = e.ProgressPercentage;


            }
            catch (Exception)
            {

                throw;
            }
        }

        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            try
            {
                if (!e.Cancelled && e.Error == null)
                {
                    progressBar1.Value = 100;
                }

            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
